from config import URL
import logging


class RegLoginApi:

    def __init__(self, session):
        self.session = session

    # 获取图片验证码接口
    def get_img_verify_code(self, r):
        url = URL + f'/common/public/verifycode1/{r}'
        resp = self.session.get(url=url)
        print(f'获取图片验证码接口返回的状态码：{resp.status_code}')
        logging.info(f'获取图片验证码接口返回的状态码：{resp.status_code}')
        return resp

    # 获取短信验证码接口
    def get_phone_verify_code(self, body):
        url = URL + "/member/public/sendSms"
        resp = self.session.post(url=url, data=body)
        print(f'获取短信验证码接口响应体数据：{resp.json()}')
        logging.info(f'获取短信验证码接口响应体数据：{resp.json()}')
        return resp

    # 注册接口
    def user_register(self, body):
        url = URL + '/member/public/reg'
        resp = self.session.post(url=url, data=body)
        print(f'注册接口响应体数据：{resp.json()}')
        logging.info(f'注册接口响应体数据：{resp.json()}')
        return resp

    # 登录接口
    def user_login(self, body):
        url = URL + '/member/public/login'
        resp = self.session.post(url=url, data=body)
        print(f'登陆接口响应体数据：{resp.json()}')
        logging.info(f'登陆接口响应体数据：{resp.json()}')
        return resp
